using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.Filters;
using Microsoft.AspNetCore.Mvc.ModelBinding;
using Microsoft.AspNetCore.Mvc.ViewFeatures;
using ShopForWeb.Dtos.ViewModel;

namespace ShopForWeb.Api.Utils.Filters
{
  public class GlobalExceptionFilter : Attribute, IExceptionFilter
  {
    public void OnException(ExceptionContext context)
    {
      //ajax 请求
        context.Result = new JsonResult(new ResponseView()
        {
          Code = 500,
          Message = context.Exception.Message
        });
      context.ExceptionHandled = true;
    }
  }
}
